﻿using Bottle.CommunityForum.IBLL;
using Bottle.CommunityForum.Model;
using Bottle.CommunityForum.Model.Enum;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Bottle.CommunityForum.BLL
{
    public partial class PageInfoService : BaseService<PageInfo>, IPageInfoService
    {
        /// <summary>
        /// 多条件查询
        /// </summary>
        /// <typeparam name="S"></typeparam>
        /// <param name="queryPageParam"></param>
        /// <param name="ordlambda"></param>
        /// <returns></returns>
        public IQueryable<PageInfo> QueryWhereLoadPage<S>(Model.Param.PageInfoParam queryPageParam, System.Linq.Expressions.Expression<Func<PageInfo, S>> ordlambda)
        {
            //页面的正常状态
            int delNormal = (int)PageEnum.StateNormal;
            //查询出所有正常状态的页面
            var Param = Db.PageInfoDal.QueryEntitys(p => p.state == delNormal);
            //获取总数
            queryPageParam.totle = Param.Count();
            //排序
            if (queryPageParam.isOrder)
            {
                //正序
                Param = Param.OrderBy(ordlambda)
                    .Skip(queryPageParam.pageSize * (queryPageParam.pageIndex - 1))
                    .Take(queryPageParam.pageSize)
                    .AsQueryable();
            }
            else
            {
                //倒序
                Param = Param.OrderByDescending(ordlambda)
                    .Skip(queryPageParam.pageSize * (queryPageParam.pageIndex - 1))
                    .Take(queryPageParam.pageSize)
                    .AsQueryable();
            }

            return Param;
        }
    }
}
